package com.javaweb.blogcite.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.javaweb.blogcite.mapper.BannerMapper;
import com.javaweb.blogcite.pojo.Banner;
import com.javaweb.blogcite.service.BannerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;

    @Override
    public List<Banner> listAllBanners() {
        return bannerMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public boolean updateBanner(List<Banner> bannerList) {
        int rows = 0;
        for (Banner banner : bannerList) {
            UpdateWrapper<Banner> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("id", banner.getId())
                    .set("title", banner.getTitle())
                    .set("description", banner.getDescription())
                    .set("big_img", banner.getBigImg())
                    .set("mid_img", banner.getMidImg());
            rows += bannerMapper.update(null, updateWrapper);
        }
        return rows > 0;
    }

}
